#ifndef MINUNIT_H
#define MINUNIT_H


extern char assertion_errors[];

#include <math.h> 
#include <stdio.h>
#include <string.h>


#define mu_assert(message, test)do{ if (!(test)){ strcat(assertion_errors,"*** FAILURE: "); strcat(assertion_errors,message); strcat(assertion_errors,"\n"); } }while(0)

#define mu_run_test(test)do{ char* message = test(); tests_run++; if (message){ strcat(test_errors,assertion_errors); strcpy(assertion_errors,""); } }while (0)


int mu_equal_abs_tolerance (double x, double y, double tol)
{ 
	// returns 1 if x and y are within tol of each other
	
	int return_value = 0;

	return_value = (tol - fabs(x-y)) > 0 ? 1 : 0;

	return return_value;
}

int mu_equal_rel_tolerance (double x, double relativeTo, double pct)
{
	// returns 1 if x is within pct of relativeTo
	//   Note that this is directional
	//   First calculate the range for an acceptable x
	//   Then see if x falls within the range
	
	int return_value = 0;
	double min = 0.0;
	double max = 0.0;

	min = relativeTo * (1.0 - pct);
	max = relativeTo * (1.0 + pct);

	return_value = (x > min) && (x < max) ? 1 : 0;	

	return return_value;
}

#endif